<?php

if (!defined('IN_ADMIN')) {
    exit('Access Denied');
}

$mpurl = 'admin.php?ac=resource';
$list = array();
if ($_GET ['op'] == "detail") {
    // 日记详情
    $id = intval($_GET ['id']);
} elseif ($_GET['op'] == "addManageResource") {
    $param			=  $_GET;
    $param['do']	=  'addManageResource';
    $param['format']	=	'json';
    $content = get_api_content($_SC ['apiurl'], $param);
    $content = json_decode($content);
    if ($content->resultData == 1) {
        $msg = "操作成功!";
        cpmessage($msg);
    }
    $msg = "操作失败，请重试一次!";
    if ($content->errorNo) {
        $msg .= "errorNo:" . $content->errorNo;
    }
    cpmessage($msg);
}elseif ($_GET['op'] == "delManageResource") {
    $param			=  $_GET;
    $param['do']	=  'delManageResource';
    $param['format']	=	'json';
    $content = get_api_content($_SC ['apiurl'], $param);
    $content = json_decode($content);
    if ($content->resultData == 1) {
        $msg = "操作成功!";
        cpmessage($msg);
    }
    $msg = "操作失败，请重试一次!";
    if ($content->errorNo) {
        $msg .= "errorNo:" . $content->errorNo;
    }
    cpmessage($msg);
}elseif ($_GET['op'] == "getManageResource") {
    $param				=  $_GET;
    $param['do']		=  'getManageResource';
    $param['format']	=  'json';
    
    $content = get_api_content($_SC ['apiurl'], $param);
    $content = json_decode($content);
    $list   =  object_to_array($content->resultData);
    
    $thumbnail = json_decode($list['thumbnail']);
    $viewurl   = json_decode($list['viewurl']);
    $type 	= array($list['type']	=>	'checked');
    $system = array($list['system']	=>	'checked');
    include_once template("admin/".'resource_info');
    exit;
}elseif ($_GET['op'] == "modManageResource") {
    $param				=  $_GET;
    $param['do']		=  'modManageResource';
    $param['format']	=  'json';
   
    $content = get_api_content($_SC ['apiurl'], $param);
    $content = json_decode($content);
    if ($content->resultData == 1) {
        $msg = "操作成功!";
        cpmessage($msg);
    }
    $msg = "操作失败，请重试一次!";
    if ($content->errorNo) {
        $msg .= "errorNo:" . $content->errorNo;
    }
    cpmessage($msg);
}else {
	$param	=  $_GET;
	$param['do']		=	'getManageResourceList';
    $param['format']	=	'json';
	$start   			=   intval($_GET ['start']) > 0 ? intval($_GET ['start']) : 0;
	$perpage 			=   intval($_GET ['perpage']) > 0 ? intval($_GET ['perpage']) : 20;
	$param['start']		=	$start;
	$param['perpage']	=	$perpage;
// 	echo '<pre>';var_dump($param);exit;
	$content  =  get_api_content($_SC ['apiurl'], $param);
	$content  =  json_decode($content);
	$result   =  object_to_array($content->resultData);
	
	// 搜索条件
	$intkeys = array(
			'id',
			'time',
			'type',
			'system',
	);
	
	//条件恢复
	$orderbyArr		=	array($param['orderby']	 => " selected");
	$orderscArr 	=	array($param['ordersc']  => " selected");
	$perpageArr 	=	array($param['perpage']  => " selected");
	$type 			=	array($param['type'] 	 => " selected");
	$system 		=	array($param['system']   => " selected");
	$name 			=	array($param['name']   	 => " selected");
	$id				=	$param['id'];
	$timeArr		=	array($param['time1'],   $param['time2']);
	
	// page
	$sort 		=   '&ordersc='.$param['ordersc'];
	$op 		=	'&op=1';
	$mpurl	   .= 	$diaryList['urls'].$sort.$op;
	$pageurl 	= 	multi($start, $perpage, $mpurl);
	$nextpurl 	= 	$pageurl['next'];
	$prevpurl 	= 	$pageurl['prev'];
	$mpurl 		= 	$pageurl['urls'];
	$firstpurl  = 	$pageurl['first'];
	$nowPage	=	$start/$perpage + 1;
	$nowNum		=	$nowPage*$perpage;
	
	$perpages = array(
			$perpage => ' selected'
	);
}






